﻿using JetBlack.IO;

namespace JetBlack.SimpleTopicBus.Messages
{
    /// <summary>
    /// A message which requests a subscription to a given topic.
    /// </summary>
    internal class SubscriptionRequest : Message
    {
        public readonly string Topic;
        public readonly bool IsAdd;

        public SubscriptionRequest(string topic, bool isAdd)
            : base(MessageType.SubscriptionRequest)
        {
            Topic = topic;
            IsAdd = isAdd;
        }

        new static public SubscriptionRequest Read(NetworkReader reader)
        {
            string topic = reader.ReadString();
            bool isAdd = reader.ReadBoolean();
            return new SubscriptionRequest(topic, isAdd);
        }

        public override NetworkWriter Write(NetworkWriter writer)
        {
            base.Write(writer);
            writer.Write(Topic);
            writer.Write(IsAdd);
            return writer;
        }

        public override string ToString()
        {
            return string.Format("{0} {1} {2}", MessageType, Topic, IsAdd);
        }
    }
}
